var api = require('../../../utils/api.js')
var $ = require('../../../utils/util.js')
var regeneratorRuntime = require('../../../utils/runtime.js')
var app = getApp()


Page({
  data: {
    hasMore: true,// 判断 数据是否全部加载完
    isLodingLock: true, //锁 防止数据加载
    pageList: [], //分页数据列表
    pageNum: 1, //页码
    isShowKong: false, // 是否是空
    keyword:'', // 搜索关键字 
    currentTab: 0, // 当前选中的tab
    nav: [
      { name: '未处理', type: 0, num: 0, color: '#dd524d', icon:'icon-shijian' },
      { name: '已处理', type: 1, num: 0,  color: '#16304f', icon: 'icon-tick' }
    ], // tab
    isShowTime: false , // 是否显示时间弹框
    isLose: false, // 打开忽略弹框
    rec: '', // 单
  },

  onLoad: function (options) {
    this.getPagServer(1, true) //获取分页数据  
    // app._total({ type: 1, is_all:1}).then((res)=>{
    //   var nav = this.data.nav
    //   nav[0].num = res.data.un_deal
    //   nav[1].num = res.data.to_deal
    //   this.setData({nav})
    // })
  },
  onShow: function () {
    // this.getPagServer(1, true) //获取分页数据  
    app._total({ type: 1, is_all:1}).then((res)=>{
      var nav = this.data.nav
      nav[0].num = res.data.un_deal
      nav[1].num = res.data.to_deal
      this.setData({nav})
    })
  },

  onReachBottom() { //滑动到底部触发
    this.loadingMore()
  },
  onPullDownRefresh: function () { // 下拉刷新
    this.getPagServer(1, true) //获取分页数据
  },


  loadingMore: function () {  // 加载更多
    console.log(this.data.isLodingLock, 111)
    if (this.data.isLodingLock) {
      this.setData({
        isLodingLock: false
      })

      this.getPagServer()
    }
  },

  getPagServer(pageNum, isClickTab = false) { //分页  
    var params = {
      pageNum: pageNum == 1 ? 1 : this.data.pageNum,
      pageSize: 10,
      type: this.data.nav[this.data.currentTab].type,
      keyword: this.data.keyword
    } 
    $.getPageList(api, this, api.warningManage.getList, params, isClickTab).then((res) => {
      wx.stopPullDownRefresh() // 接口数据请求完停止刷新
    })
  },

  //##input 输入##
  input_handle(e) {
    this.setData({
      [e.currentTarget.dataset.key]: e.detail.value
    })
  },
  //##input 输入##

  keywordConfirmHandle(){ // 搜索输入框 
    // if($.isNull(this.data.keyword)){
      // $.toast('请输入内容') 
    // }else {
      this.getPagServer(1, true) //获取分页数据
    // }

  },

  tabHanlde(e) {
    var { index } = e.detail
    this.setData({
      currentTab: index
    })
    this.getPagServer(1, true) //获取分页数据
  },
  timeConfirmHandle(e){ // 时间组件传出来的数据
    var { time, key} = e.detail
    console.log(time, key)
  },
  openTimeHandle(e){ // 打开时间弹框
    this.setData({
      isShowTime: true
    })
  },
  openLoseHandle(e){ // 打开忽略弹框
    var {item} = $.detail(e)
    this.setData({
      isLose: true,
      id: item.id
    })
  },
  setUpdateHandle() { // 告警忽略处理  
      var params = {
        user_name: wx.getStorageSync('user_name'),
        id: this.data.id
      }
      api.$post(api.warningManage.setUpdate, params).then((res) => {
        this.getPagServer(1, true) //获取分页数据  
        app._total({ type: 1, is_all:1}).then((res)=>{
          var nav = this.data.nav
          nav[0].num = res.data.un_deal
          nav[1].num = res.data.to_deal
          this.setData({nav})
        })
      }) 
  }, 
  toRobManageRushSend(e){ // 转抢修
    var {item} = $.detail(e)
    console.log(item);
    $.linkurl(`/pages/robManage/robManageRushSend/robManageRushSend?info=${JSON.stringify(item)}&u_i=1`)
  },
  toDefectManageFlawRegister(e){ // 转缺陷
    var { item } = $.detail(e)
    item.source='告警'; 
    $.linkurl(`/pages/defectManage/defectManageFlawRegister/defectManageFlawRegister?info=${JSON.stringify(item)}&type=0`)
  },
  toWarningManageAntvHandle(e){ // 去antv 
    var { item } = $.detail(e)
    $.linkurl(`/pages/warningManage/warningManageAntv/warningManageAntv?info=${JSON.stringify(item)}`)
  }
})